package com.octopus.tree;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import com.octopus.string.StringUtils;

public class Unit {
	private String name;
	private String kind;
	private Integer startIndex;
	private Integer endIndex;
	private Properties properties;

	public Unit() {
		properties = new Properties();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getKind() {
		return kind;
	}

	public void setKind(String kind) {
		this.kind = kind;
	}

	public void addProperty(String name, String value) {
		this.properties.setProperty(name, value);
	}

	public void removeProperty(String name) {
		this.properties.remove(name);
	}

	public List<String> getPropertyKeyList() {
		List<String> result = new ArrayList<String>();
		Set<Object> keySet = this.properties.keySet();
		if (keySet.size() > 0) {
			Iterator<Object> iterator = keySet.iterator();
			while (iterator.hasNext()) {
				result.add((String) iterator.next());
			}
		}
		return result;
	}
	
	public int propertySize(){
		return this.properties.size();
	}

	public String getPropertyValue(String name) {
		return this.properties.getProperty(name);
	}
	
	public Integer getStartIndex() {
		return startIndex;
	}

	public void setStartIndex(Integer startIndex) {
		this.startIndex = startIndex;
	}

	public Integer getEndIndex() {
		return endIndex;
	}

	public void setEndIndex(Integer endIndex) {
		this.endIndex = endIndex;
	}

	@Override
	public String toString(){
		return StringUtils.concat("(Unit:n=",name,":k=",kind,":si=",String.valueOf(startIndex),":ei=",String.valueOf(endIndex),":p=(",String.valueOf(properties),"))");
	}
}